/*   1:    */ package com.rinsi.app.tzck;
/*   2:    */ 
/*   3:    */ import com.rinsi.core.contoller.CoreSimpleController;
/*   4:    */ import com.rinsi.core.service.CoreSimpleService;
/*   5:    */ import com.rinsi.util.CodeUtil;
/*   6:    */ import com.rinsi.util.FileUtil;
/*   7:    */ import com.rinsi.util.MapUtil;
/*   8:    */ import java.io.BufferedInputStream;
/*   9:    */ import java.io.BufferedOutputStream;
/*  10:    */ import java.io.File;
/*  11:    */ import java.io.FileInputStream;
/*  12:    */ import java.io.PrintWriter;
/*  13:    */ import java.net.URLDecoder;
/*  14:    */ import java.util.List;
/*  15:    */ import java.util.Map;
/*  16:    */ import javax.servlet.ServletContext;
/*  17:    */ import javax.servlet.http.HttpServletRequest;
/*  18:    */ import javax.servlet.http.HttpServletResponse;
/*  19:    */ import org.springframework.beans.factory.annotation.Autowired;
/*  20:    */ import org.springframework.stereotype.Controller;
/*  21:    */ import org.springframework.ui.ModelMap;
/*  22:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  23:    */ import org.springframework.web.bind.annotation.RequestParam;
/*  24:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  25:    */ import org.springframework.web.multipart.MultipartFile;
/*  26:    */ 
/*  27:    */ @Controller
/*  28:    */ @RequestMapping({"/tzck"})
/*  29:    */ public class TzckController
/*  30:    */   extends CoreSimpleController
/*  31:    */ {
/*  32:    */   @Autowired
/*  33:    */   private TzckService tzckService;
/*  34:    */   
/*  35:    */   @RequestMapping({"/fileList"})
/*  36:    */   public Map<String, Object> fileList(ModelMap model, HttpServletRequest request)
/*  37:    */   {
/*  38: 41 */     Map<String, Object> rMap = servce().getRMap();
/*  39:    */     try
/*  40:    */     {
/*  41: 45 */       Map<String, Object> params = servce().getParams(model);
/*  42:    */       
/*  43: 47 */       String mod = MapUtil.getString((Map)model.get("module"), "MODULE_NO");
/*  44:    */       
/*  45: 49 */       String filepath = request.getServletContext().getRealPath("") + "/dwf/";
/*  46:    */       
/*  47: 51 */       String ID = request.getParameter("ID") + "/";
/*  48:    */       
/*  49: 53 */       filepath = filepath + ID;
/*  50:    */       
/*  51: 55 */       List<Map<String, Object>> files = FileUtil.getFileList(filepath);
/*  52:    */       
/*  53: 57 */       params.put("MODULE_NO", mod);
/*  54:    */       
/*  55: 59 */       model.putAll(params);
/*  56:    */       
/*  57: 61 */       model.put("files", files);
/*  58:    */       
/*  59: 63 */       model.put("viewPage", "/commons/commons_filelist.jsp");
/*  60:    */     }
/*  61:    */     catch (Exception e)
/*  62:    */     {
/*  63: 67 */       rMap.put("success", Boolean.valueOf(false));
/*  64:    */       
/*  65: 69 */       rMap.put("message", e.getMessage());
/*  66:    */     }
/*  67: 73 */     return rMap;
/*  68:    */   }
/*  69:    */   
/*  70:    */   @ResponseBody
/*  71:    */   @RequestMapping({"/upload"})
/*  72:    */   public void upload(@RequestParam MultipartFile file, HttpServletRequest request, HttpServletResponse response)
/*  73:    */   {
/*  74:    */     try
/*  75:    */     {
/*  76: 83 */       String filepath = request.getServletContext().getRealPath("") + "/dwf/";
/*  77:    */       
/*  78: 85 */       String ID = request.getParameter("ID") == null ? "" : request.getParameter("ID");
/*  79:    */       
/*  80: 87 */       filepath = filepath + ID + "/";
/*  81:    */       
/*  82: 89 */       FileUtil.deleteDirectory(filepath);
/*  83:    */       
/*  84: 91 */       FileUtil.createFile(filepath, file.getOriginalFilename(), file.getBytes());
/*  85:    */       
/*  86: 93 */       response.setCharacterEncoding("UTF-8");
/*  87:    */       
/*  88: 95 */       response.getWriter().print(file.getOriginalFilename());
/*  89:    */       
/*  90: 97 */       this.tzckService.updateTzurl(ID, CodeUtil.code(FileUtil.getBaseFileName(file)) + "." + FileUtil.getFileType(file));
/*  91:    */     }
/*  92:    */     catch (Exception e)
/*  93:    */     {
/*  94:101 */       e.printStackTrace();
/*  95:    */     }
/*  96:    */   }
/*  97:    */   
/*  98:    */   @RequestMapping({"/fileRemove"})
/*  99:    */   public Map<String, Object> fileRemove(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response)
/* 100:    */   {
/* 101:110 */     Map<String, Object> rMap = servce().getRMap();
/* 102:    */     try
/* 103:    */     {
/* 104:114 */       String filepath = request.getServletContext().getRealPath("") + "/dwf/";
/* 105:    */       
/* 106:116 */       String ID = request.getParameter("ID") == null ? "" : request.getParameter("ID");
/* 107:    */       
/* 108:118 */       filepath = filepath + ID + "/";
/* 109:    */       
/* 110:120 */       FileUtil.deleteExistedFile(filepath, filename);
/* 111:    */       
/* 112:122 */       this.tzckService.updateTzurl(ID, null);
/* 113:    */     }
/* 114:    */     catch (Exception e)
/* 115:    */     {
/* 116:126 */       rMap.put("success", Boolean.valueOf(false));
/* 117:    */       
/* 118:128 */       rMap.put("message", e.getMessage());
/* 119:    */       
/* 120:130 */       e.printStackTrace();
/* 121:    */     }
/* 122:134 */     return rMap;
/* 123:    */   }
/* 124:    */   
/* 125:    */   @RequestMapping({"/download"})
/* 126:    */   public void download(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response)
/* 127:    */   {
/* 128:142 */     BufferedInputStream bis = null;
/* 129:    */     
/* 130:144 */     BufferedOutputStream bos = null;
/* 131:    */     try
/* 132:    */     {
/* 133:148 */       File file = new File(URLDecoder.decode(filename, "utf-8"));
/* 134:    */       
/* 135:150 */       String filepath = request.getServletContext().getRealPath("") + "/dwf/";
/* 136:    */       
/* 137:152 */       String ID = request.getParameter("ID") == null ? "" : request.getParameter("ID");
/* 138:    */       
/* 139:154 */       filepath = filepath + ID + "/";
/* 140:    */       
/* 141:156 */       filepath = filepath + CodeUtil.code(FileUtil.getBaseFileName(file)) + "." + FileUtil.getFileType(file);
/* 142:    */       
/* 143:158 */       File finalFile = new File(filepath);
/* 144:    */       
/* 145:160 */       long fileLength = finalFile.length();
/* 146:    */       
/* 147:162 */       response.setContentType("text/html;charset=UTF-8");
/* 148:    */       
/* 149:164 */       request.setCharacterEncoding("UTF-8");
/* 150:    */       
/* 151:166 */       response.setContentType("application/x-msdownload;");
/* 152:    */       
/* 153:168 */       response.setHeader("Content-disposition", "attachment; filename=" + new String(filename.getBytes("gb2312"), "iso-8859-1"));
/* 154:    */       
/* 155:170 */       response.setHeader("Content-Length", String.valueOf(fileLength));
/* 156:    */       
/* 157:172 */       bis = new BufferedInputStream(new FileInputStream(finalFile));
/* 158:    */       
/* 159:174 */       bos = new BufferedOutputStream(response.getOutputStream());
/* 160:    */       
/* 161:176 */       byte[] buff = new byte[2048];
/* 162:    */       int bytesRead;
/* 163:180 */       while (-1 != (bytesRead = bis.read(buff, 0, buff.length)))
/* 164:    */       {
/* 165:    */         //int bytesRead;
/* 166:182 */         bos.write(buff, 0, bytesRead);
/* 167:    */       }
/* 168:    */     }
/* 169:    */     catch (Exception e)
/* 170:    */     {
/* 171:187 */       e.printStackTrace();
/* 172:    */       try
/* 173:    */       {
/* 174:192 */         if (bis != null) {
/* 175:193 */           bis.close();
/* 176:    */         }
/* 177:195 */         if (bos != null) {
/* 178:196 */           bos.close();
/* 179:    */         }
/* 180:    */       }
/* 181:    */       catch (Exception e1)
/* 182:    */       {
/* 183:200 */         e1.printStackTrace();
/* 184:    */       }
/* 185:    */     }
/* 186:    */     finally
/* 187:    */     {
/* 188:    */       try
/* 189:    */       {
/* 190:192 */         if (bis != null) {
/* 191:193 */           bis.close();
/* 192:    */         }
/* 193:195 */         if (bos != null) {
/* 194:196 */           bos.close();
/* 195:    */         }
/* 196:    */       }
/* 197:    */       catch (Exception e)
/* 198:    */       {
/* 199:200 */         e.printStackTrace();
/* 200:    */       }
/* 201:    */     }
/* 202:    */   }
/* 203:    */   
/* 204:    */   public CoreSimpleService servce()
/* 205:    */   {
/* 206:208 */     return this.tzckService;
/* 207:    */   }
/* 208:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.app.tzck.TzckController
 * JD-Core Version:    0.7.0.1
 */